package com.asset.salesforce.model;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

import com.asset.salesforce.jacksonConvertor.CustomDateSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@SuppressWarnings("serial")
@XmlRootElement
@Entity
@Table(name = "employee")
public class Employee implements Serializable {
	
	@JsonInclude(Include.NON_NULL)
	private Integer id;
	@JsonIgnore
	private File photo;
	@JsonInclude(Include.NON_NULL)
	   
	private Integer photoId;
	@JsonInclude(Include.NON_NULL)
	private String empInfo;
	@JsonInclude(Include.NON_NULL)
	private String fName;
	@JsonInclude(Include.NON_NULL)
	private String lName;
	@JsonInclude(Include.NON_NULL)
	private String nickName;
	@JsonInclude(Include.NON_NULL)
	private String email;
	@JsonIgnore
	private Company company;
	@JsonIgnore
	private Country country;
	@JsonInclude(Include.NON_NULL)
	   
	private Integer countryId;
	@JsonIgnore
	private JobTitle jobTitle;
	@JsonInclude(Include.NON_NULL)
	private Integer jobTitleId;
	@JsonIgnore
	private Department dept;
	@JsonInclude(Include.NON_NULL)
	   
	private Integer deptId;
	@JsonIgnore
	private Employee manager;
	@JsonInclude(Include.NON_NULL)
	   
	private Integer managerId;
	@JsonInclude(Include.NON_NULL)
	private Date registerDate;
	@JsonInclude(Include.NON_NULL)
	private Boolean isActive;
	@JsonInclude(Include.NON_NULL)
	private Boolean isOwner;
	@JsonInclude(Include.NON_NULL)
	private Boolean firstLogin;
	@JsonInclude(Include.NON_NULL)
	@JsonIgnore
	private Set<Employee> employees;
	@JsonInclude(Include.NON_NULL)
	private Boolean isFollowed;
	@JsonInclude(Include.NON_NULL)
	private Date dateCreated;
	@JsonInclude(Include.NON_NULL)
	private Date dateModified;
	@JsonInclude(Include.NON_NULL)
	   
	private Integer companyId;
	/**
	 * @return the employees
	 */
	@OneToMany(mappedBy="manager",fetch=FetchType.EAGER)
	public Set<Employee> getEmployees() {
		return employees;
	}
	/**
	 * @param employees the employees to set
	 */
	public void setEmployees(Set<Employee> employees) {
		this.employees = employees;
	}
	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="employee_id_seq")
	@SequenceGenerator(name="employee_id_seq",sequenceName="employee_id_seq",allocationSize=1)
	public Integer getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	/**
	 * @return the photoId
	 */
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "photo_id")
	public File getPhoto() {
		return photo;
	}
	/**
	 * @param photoId the photoId to set
	 */
	
	public void setPhoto(File photo) {
		this.photo = photo;
	}
	/**
	 * @return the empInfo
	 */
	@Column(name="emp_info")
	public String getEmpInfo() {
		return empInfo;
	}
	/**
	 * @param empInfo the empInfo to set
	 */
	public void setEmpInfo(String empInfo) {
		this.empInfo = empInfo;
	}
	/**
	 * @return the fName
	 */
	@Column(name="f_name")
	public String getfName() {
		return fName;
	}
	/**
	 * @param fName the fName to set
	 */
	
	public void setfName(String fName) {
		this.fName = fName;
	}
	/**
	 * @return the lName
	 */
	@Column(name="l_name")
	public String getlName() {
		return lName;
	}
	/**
	 * @param lName the lName to set
	 */
	public void setlName(String lName) {
		this.lName = lName;
	}
	/**
	 * @return the nickName
	 */
	@Column(name="nick_name")
	public String getNickName() {
		return nickName;
	}
	/**
	 * @param nickName the nickName to set
	 */
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	/**
	 * @return the email
	 */
	@Column(name="email")
	public String getEmail() {
		return email;
	}
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @return the companyId
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="company_id")
	public Company getCompany() {
		return company;
	}
	/**
	 * @param companyId the companyId to set
	 */
	public void setCompany(Company company) {
		this.company = company;
	}
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="country_id")
	public Country getCountry() {
		return country;
	}
	public void setCountry(Country country) {
		this.country = country;
	}
	/**
	 * @return the jobTitleId
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="job_title_id")
	public JobTitle getJobTitle() {
		return jobTitle;
	}
	/**
	 * @param jobTitleId the jobTitleId to set
	 */
	public void setJobTitle(JobTitle jobTitle) {
		this.jobTitle = jobTitle;
	}
	/**
	 * @return the debtId
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="dept_id")
	public Department getDept() {
		return dept;
	}
	/**
	 * @param debtId the debtId to set
	 */
	public void setDept(Department dept) {
		this.dept = dept;
	}
	/**
	 * @return the managerId
	 */
	@ManyToOne
	@JoinColumn(name="manager_id")
	public Employee getManager() {
		return manager;
	}
	
	
	/**
	 * @param managerId the managerId to set
	 */
	public void setManager(Employee manager) {
		this.manager = manager;
	}
	/**
	 * @return the registerDate
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="register_date")
	@JsonSerialize(using= CustomDateSerializer.class)
	public Date getRegisterDate() {
		return registerDate;
	}
	/**
	 * @param registerDate the registerDate to set
	 */
	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}
	/**
	 * @return the isActive
	 */
	@Column(name="is_active")
	public Boolean getIsActive() {
		return isActive;
	}
	/**
	 * @param isActive the isActive to set
	 */
	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}
	/**
	 * @return the isOwner
	 */
	@Column(name="is_owner")
	public Boolean getIsOwner() {
		return isOwner;
	}
	/**
	 * @param isOwner the isOwner to set
	 */
	public void setIsOwner(Boolean isOwner) {
		this.isOwner = isOwner;
	}
	/**
	 * @return the isFollowed
	 */
	@Transient   
	public Boolean getIsFollowed() {
		return isFollowed;
	}
	/**
	 * @param isFollowed the isFollowed to set
	 */
	public void setIsFollowed(Boolean isFollowed) {
		this.isFollowed = isFollowed;
	}
	
	@Column(name="first_login")
	public Boolean getFirstLogin() {
		return firstLogin;
	}
	public void setFirstLogin(Boolean firstLogin) {
		this.firstLogin = firstLogin;
	}
	/**
	 * @return the dateCreated
	 */
	@Temporal(value=TemporalType.TIMESTAMP)
	@Column(name="date_created")
	@JsonSerialize(using= CustomDateSerializer.class)
	public Date getDateCreated() {
		return dateCreated;
	}
	/**
	 * @param dateCreated the dateCreated to set
	 */
	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}
	/**
	 * @return the dateModified
	 */
	@Temporal(value = TemporalType.TIMESTAMP)
	@Column(name="date_modified")
	@JsonSerialize(using= CustomDateSerializer.class)
	public Date getDateModified() {
		return dateModified;
	}
	/**
	 * @param dateModified the dateModified to set
	 */
	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String str="";
		if(this.id!=null){
			str+="{\"id\"        :\""+this.id+"\"";
		}
		if(this.photo!=null){
			str+=",\"photoId\"        :"+this.photo.getId()+"";
		}
		if(this.empInfo!=null){
			str+=",\"empInfo\"        :\""+this.empInfo+"\"";
		}
		if(this.fName!=null){
			str+=",\"fName\"        :\""+this.fName+"\"";
		}
		if(this.lName!=null){
			str+=",\"lName\"        :\""+this.lName+"\"";
		}
		if(this.nickName!=null){
			str+=",\"nickName\"        :\""+this.nickName+"\"";
		}
		if(this.email!=null){
			str+=",\"email\"        :\""+this.email+"\"";
		}
		if(this.company!=null){
			str+=",\"companyId\"        :"+this.company.getId()+"";
		}
		if(this.country!=null){
			str+=",\"countryId\"        :"+this.country.getId()+"";
		}
		if(this.jobTitle!=null){
			str+=",\"jobTitleId\"        :"+this.jobTitle.getId()+"";
		}

		if(this.registerDate!=null){
			str+=",\"registerDate\"        :\""+this.registerDate+"\"";
		}
		if(this.isActive!=null){
			str+=",\"isActive\"        :\""+this.isActive+"\"";
		}
		if(this.isOwner!=null){
			str+=",\"isOwner\"        :\""+this.isOwner+"\"";
		}
		
		if(this.firstLogin!=null){
			str+=",\"firstLogin\"        :\""+this.firstLogin+"\"";
		}

		if(this.isFollowed!=null){
			str+=",\"isFollowed\"        :\""+this.isFollowed+"\"";
		}
		if(this.dateCreated!=null){
			str+=",\"dateCreated\"        :\""+this.dateCreated+"\"";
		}
		if(this.dateModified!=null){
			str+=",\"dateModified\"        :\""+this.dateModified+"\"";
		}
		str+="}";
//		String str = 
//				
//				",\"photo\"        :"+this.photo+
//				",\"empInfo\"        :\""+this.empInfo+"\""+
//				",\"fName\"        :\""+this.fName+"\""+
//				",\"lName\"        :\""+this.lName+"\""+
//				",\"nickName\"        :\""+this.nickName+"\""+
//				",\"email\"        :\""+this.email+"\""+
//				",\"company\"        :"+this.company+
//				",\"country\"        :"+this.country+
//				",\"jobTitle\"        :"+this.jobTitle+
////				",\"dept\"        :\""+this.dept+"\""+
////				",\"manager\"        :\""+manager+"\""+
//				",\"registerDate\"        :\""+this.registerDate+"\""+
//				",\"isActive\"        :\""+this.isActive+"\""+
//				",\"isOwner\"        :\""+this.isOwner+"\""+
//				",\"firstLogin\"        :\""+this.firstLogin+"\""+
//				",\"isFollowed\"        :\""+this.isFollowed+"\""+
//				",\"dateCreated\"        :\""+this.dateCreated+"\""+
//				",\"dateModified\"        :\""+this.dateModified+"\""+
//				"}";
		return str;
	}
	public String  toList(List<Employee> elements){
		String str= new String("");
		for(Employee element : elements){
			if(elements.size()-1 == elements.indexOf(element)){
				str+=element.toString()+"]}";
			}else{
				str +=element.toString()+",";
			}
		}
		return str;		
	}
	/**
	 * @return the companyId
	 */
	@Transient
	public Integer getCompanyId() {
		return companyId;
	}
	/**
	 * @param companyId the companyId to set
	 */
	public void setCompanyId(Integer companyId) {
		this.companyId = companyId;
	}
	/**
	 * @return the photoId
	 */
	@Transient
	public Integer getPhotoId() {
		return photoId;
	}
	/**
	 * @param photoId the photoId to set
	 */
	public void setPhotoId(Integer photoId) {
		this.photoId = photoId;
	}
	/**
	 * @return the countryId
	 */
	@Transient
	public Integer getCountryId() {
		return countryId;
	}
	/**
	 * @param countryId the countryId to set
	 */
	public void setCountryId(Integer countryId) {
		this.countryId = countryId;
	}
	/**
	 * @return the jobTitleId
	 */
	@Transient
	public Integer getJobTitleId() {
		return jobTitleId;
	}
	/**
	 * @param jobTitleId the jobTitleId to set
	 */
	public void setJobTitleId(Integer jobTitleId) {
		this.jobTitleId = jobTitleId;
	}
	/**
	 * @return the deptId
	 */
	@Transient
	public Integer getDeptId() {
		return deptId;
	}
	/**
	 * @param deptId the deptId to set
	 */
	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}
	/**
	 * @return the managerId
	 */
	@Transient
	public Integer getManagerId() {
		return managerId;
	}
	/**
	 * @param managerId the managerId to set
	 */
	public void setManagerId(Integer managerId) {
		this.managerId = managerId;
	}
}